
    
    
    Pygments — Pygments
    
    
    
    
    
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '/',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '',
        HAS_SOURCE:  false
      };
    
    
    
    
    
    
    
    
    
    
      // intelligent scrolling of the sidebar content
      $(window).scroll(function() {
        var sb = $('.sphinxsidebarwrapper');
        var win = $(window);
        var sbh = sb.height();
        var offset = $('.sphinxsidebar').position()['top'];
        var wintop = win.scrollTop();
        var winbot = wintop + win.innerHeight();
        var curtop = sb.position()['top'];
        var curbot = curtop + sbh;
        // does sidebar fit in window?
        if (sbh < win.innerHeight()) {
          // yes: easy case -- always keep at the top
          sb.css('top', $u.min([$u.max([0, wintop - offset - 10]),
                                $(document).height() - sbh - 200]));
        } else {
          // no: only scroll if top/bottom edge of sidebar is at
          // top/bottom edge of window
          if (curtop > wintop && curbot > winbot) {
            sb.css('top', $u.max([wintop - offset - 10, 0]));
          } else if (curtop < wintop && curbot < winbot) {
            sb.css('top', $u.min([winbot - sbh - offset - 20,
                                  $(document).height() - sbh - 200]));
          }
        }
      });
    
  
  
    
      
        
          Home
          Demo
          Languages
          FAQ
          Get it
          Docs
        
        
          
            
          
       
     
    

    
      
        
          
            
Demo entry 1487240

html generated by pygment


  Use this style:  
    
      
      manni
      
      igor
      
      xcode
      
      vim
      
      autumn
      
      vs
      
      rrt
      
      native
      
      perldoc
      
      borland
      
      tango
      
      emacs
      
      friendly
      
      monokai
      
      paraiso-dark
      
      colorful
      
      murphy
      
      bw
      
      pastie
      
      paraiso-light
      
      trac
      
      default
      
      fruity
      
      
    
  


Submitted by anonymous
  on Apr 20, 2015 at 11:15 
  Language: HTML. Code size: 11.1 kB.




Important: This entry is not yet stored in the database.

  
  
 or 

  
  




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=" />
    
    <title>Pygments &mdash; Pygments</title>
    
    <link rel="stylesheet" href="/_static/pygments14.css" type="text/css" />
    <link rel="stylesheet" href="/_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '/',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="/_static/jquery.js"></script>
    <script type="text/javascript" src="/_static/underscore.js"></script>
    <script type="text/javascript" src="/_static/doctools.js"></script>
    
    
    <link rel="shortcut icon" href="/_static/favicon.ico"/>
    <link rel="top" title="Pygments documentation" href="/" />
    <link href='http://fonts.googleapis.com/css?family=PT+Sans:300,400,700'
          rel='stylesheet' type='text/css'>
    <script type="text/javascript">
      // intelligent scrolling of the sidebar content
      $(window).scroll(function() {
        var sb = $('.sphinxsidebarwrapper');
        var win = $(window);
        var sbh = sb.height();
        var offset = $('.sphinxsidebar').position()['top'];
        var wintop = win.scrollTop();
        var winbot = wintop + win.innerHeight();
        var curtop = sb.position()['top'];
        var curbot = curtop + sbh;
        // does sidebar fit in window?
        if (sbh < win.innerHeight()) {
          // yes: easy case -- always keep at the top
          sb.css('top', $u.min([$u.max([0, wintop - offset - 10]),
                                $(document).height() - sbh - 200]));
        } else {
          // no: only scroll if top/bottom edge of sidebar is at
          // top/bottom edge of window
          if (curtop > wintop && curbot > winbot) {
            sb.css('top', $u.max([wintop - offset - 10, 0]));
          } else if (curtop < wintop && curbot < winbot) {
            sb.css('top', $u.min([winbot - sbh - offset - 20,
                                  $(document).height() - sbh - 200]));
          }
        }
      });
    </script>
  </head>
  <body role="document">
    <div class="outerwrapper">
      <div class="pageheader">
        <ul>
          <li><a href="/">Home</a></li>
          <li><a href="/demo/">Demo</a></li>
          <li><a href="/languages/">Languages</a></li>
          <li><a href="/faq/">FAQ</a></li>
          <li><a href="/download/">Get it</a></li>
          <li><a href="/docs/">Docs</a></li>
        </ul>
        <div>
          <a href="/">
            <img src="/_static/logo.png" alt="Pygments logo" />
          </a>
       </div>
     </div>
    

    <div class="document">
      <div class="documentwrapper">
        <div class="fullbodywrapper">
          <div class="body" role="main">
            
<h1 class="heading">Demo entry 1487118</h1>

<p><strong>namespace init in CS</strong></p>

<form action="/demo/1487118/" method="get" name="filter_form" id="filter_form">
  <p style="margin-top: 0"><label for="style">Use this style:</label> &nbsp;
    <select id="style" name="style" onchange="document.forms.filter_form.submit()">
      
      <option value="manni" >manni</option>
      
      <option value="igor" >igor</option>
      
      <option value="xcode" >xcode</option>
      
      <option value="vim" >vim</option>
      
      <option value="autumn" >autumn</option>
      
      <option value="vs" >vs</option>
      
      <option value="rrt" >rrt</option>
      
      <option value="native" >native</option>
      
      <option value="perldoc" >perldoc</option>
      
      <option value="borland" >borland</option>
      
      <option value="tango" >tango</option>
      
      <option value="emacs" >emacs</option>
      
      <option value="friendly" selected="selected">friendly</option>
      
      <option value="monokai" >monokai</option>
      
      <option value="paraiso-dark" >paraiso-dark</option>
      
      <option value="colorful" >colorful</option>
      
      <option value="murphy" >murphy</option>
      
      <option value="bw" >bw</option>
      
      <option value="pastie" >pastie</option>
      
      <option value="paraiso-light" >paraiso-light</option>
      
      <option value="trac" >trac</option>
      
      <option value="default" >default</option>
      
      <option value="fruity" >fruity</option>
      
    </select> &nbsp;
    <input type="submit" value="Go">
  </p>
</form>

<p>Submitted by <strong>Jesus Franco</strong>
  on Apr 17, 2015 at 17:46 <br>
  Language: CoffeeScript. Code size: 1.4 kB.
</p>



<div class="hlcode">
<div class="syntax"><pre><span class="nv">extend = </span><span class="nf">(inject, template) -&gt;</span>
  <span class="p">(</span><span class="nx">template</span><span class="p">[</span><span class="nx">prop</span><span class="p">]</span> <span class="o">=</span> <span class="nx">inject</span><span class="p">[</span><span class="nx">prop</span><span class="p">])</span> <span class="k">for</span> <span class="k">own</span> <span class="nx">prop</span> <span class="k">of</span> <span class="nx">inject</span>
  <span class="kc">null</span>

<span class="nv">init_namespace = </span><span class="nf">(nameString, obj, container) -&gt;</span>
    <span class="nx">container</span> <span class="o">?=</span> <span class="nb">window</span>
    <span class="nv">names = </span><span class="nx">nameString</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)</span>
    <span class="p">(</span><span class="nx">container</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">or=</span> <span class="p">{}</span> <span class="p">;</span>
    <span class="nv">container = </span><span class="nx">container</span><span class="p">[</span><span class="nx">name</span><span class="p">])</span> <span class="k">while</span> <span class="nv">name = </span><span class="nx">names</span><span class="p">.</span><span class="nx">shift</span><span class="p">()</span>
    <span class="nx">extend</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">container</span><span class="p">)</span>

<span class="nx">describe</span> <span class="s">&quot;Namespace DRY initializer&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
    <span class="nx">describe</span> <span class="s">&quot;A simple name init&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
        <span class="nx">it</span> <span class="s">&quot;a simple name should be available in global object&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
            <span class="nx">init_namespace</span> <span class="s">&quot;simple&quot;</span>
            <span class="nx">expect</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">simple</span><span class="p">).</span><span class="nx">toBeDefined</span><span class="p">()</span>

    <span class="nx">describe</span> <span class="s">&quot;A two levels nested name path&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
        <span class="nx">beforeEach</span> <span class="nf">-&gt;</span>
            <span class="nb">window</span><span class="p">.</span><span class="nv">simple = </span><span class="kc">null</span>
            <span class="nx">init_namespace</span> <span class="s">&quot;simple.nested&quot;</span>

        <span class="nx">it</span> <span class="s">&quot;makes available its top name in container&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
            <span class="nx">expect</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">simple</span><span class="p">).</span><span class="nx">toBeDefined</span><span class="p">()</span>
        <span class="nx">it</span> <span class="s">&quot;makes available its child name in container&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
            <span class="nx">expect</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">simple</span><span class="p">.</span><span class="nx">nested</span><span class="p">).</span><span class="nx">toBeDefined</span><span class="p">()</span>

    <span class="nx">describe</span> <span class="s">&quot;A custom passed object&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
        <span class="nx">it</span> <span class="s">&quot;set its properties to ns&#39; deepest child&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span>
            <span class="nb">window</span><span class="p">.</span><span class="nv">simple = </span><span class="kc">null</span>
            <span class="nx">init_namespace</span><span class="p">(</span><span class="s">&quot;simple.nested.ns&quot;</span><span class="p">,</span> 
                      <span class="nv">custom: </span><span class="kc">true</span>
                      <span class="nv">queryable: </span><span class="kc">false</span>
                <span class="p">)</span>
            <span class="nx">ns</span><span class="o">=</span><span class="nb">window</span><span class="p">.</span><span class="nx">simple</span><span class="p">.</span><span class="nx">nested</span><span class="p">.</span><span class="nx">ns</span>
            <span class="nx">expect</span><span class="p">(</span><span class="nx">ns</span><span class="p">.</span><span class="nx">custom</span><span class="p">).</span><span class="nx">toBeTruthy</span><span class="p">()</span>
            <span class="nx">expect</span><span class="p">(</span><span class="nx">ns</span><span class="p">.</span><span class="nx">queryable</span><span class="p">).</span><span class="nx">toBeFalsy</span><span class="p">()</span>
</pre></div>

</div>

<p>This snippet took 0.00 seconds to highlight.</p>

<p>Back to the <a href="/demo/">Entry List</a> or <a href="/">Home</a>.</p>

<p style="font-size: xx-small"><a href="/demo/1487118/delete/">Delete this entry (admin only)</a>.</p>

          </div>
        </div>
      </div>

      <div class="clearer"></div>
    </div>
      <div class="footer" role="contentinfo">
        &copy; Copyright 2014, Georg Brandl and Pygments contributors.
        Created using <a href="http://sphinx-doc.org/">Sphinx</a> . <br/>
        Pygments logo created by <a href="http://dribbble.com/joelunger">Joel Unger</a>.
        Backgrounds from <a href="http://subtlepatterns.com">subtlepatterns.com</a>.
      </div>
    </div> 
  </body>
</html>




This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).

          
        
      

      
    
      
        © Copyright 2014, Georg Brandl and Pygments contributors.
        Created using Sphinx . 
        Pygments logo created by Joel Unger.
        Backgrounds from subtlepatterns.com.
      
     
  
